import type { Article, ArticleType, User } from "@/type";

/**
 * 登录
 * @param username 用户名
 * @param password 密码
 */
export function login(username: string, password: string) {
    return useRequest<{
        access_token: string
    }>('/v1/login', {
        method: 'post',
        body: {
            username, password
        }
    })
}

/**
 * 获取登录信息
 */
export function getLoginInfo() {
    return useRequest<Omit<User, 'password'>>('/v1/getLoginInfo', {
        method: 'get',
    })
}


/**
 * 注册
 * @param data.username 用户名
 * @param data.password 密码
 * @param data.repeatPassword 重复密码
 * @param data.email 邮箱
 * @param data.code 验证码
 */
export function register(data: { username: string, password: string, repeatPassword: string, email: string, code: string }) {
    return useRequest<{
        access_token: string
    }>('/v1/register', {
        method: 'post',
        body: data
    })
}

/**
 * 首页分区数据列表
 */
export function getIndexArticleDisplayList() {
    return useRequest<{
        list: {
            title: string,
            type: ArticleType,
            recommend_list: (Article & { user: Omit<User, 'password'> })[],
        }[]
    }>('/v1/index/articleDisplayList', {
        method: 'get',
    })
}